package com.dropgame.tools;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;

public class ImageButton2 {

	Texture button;
	public TextureRegion out;
	TextureRegion in;
	public TextureRegion keyFrame;
	public Sprite sKeyFrame;
	
	public Sprite sOut;
	public Sprite sIn;
	
	InvertedInput input;
	
	private boolean touched;
	boolean released;
	boolean toggle;
	private boolean finished;
	
	public int xPos;
	public int yPos;
	
	public int touchX;
	public int touchY;
	
	int width;
	int height;
	
	float sinceTouched = 0.0f;
	
	float scale = 1.0f;
	
	public Rectangle bounds;
	
	public float speed;
	
	public ImageButton2(TextureRegion out, int xPos, int yPos){
		this.out = out;
		this.xPos = xPos;
		this.yPos = yPos;
		setTouched(false);
		bounds = new Rectangle(xPos, yPos, out.getRegionWidth(), out.getRegionHeight());
		this.speed = speed;
		keyFrame = out;
		setFinished(false);
		
		
	}
	
	public ImageButton2(TextureRegion out, TextureRegion in, int xPos, int yPos, float speed){
		this.out = out;
		this.in = in;
		this.xPos = xPos;
		this.yPos = yPos;
		setTouched(false);
		bounds = new Rectangle(xPos, yPos, out.getRegionWidth(), out.getRegionHeight());
		this.speed = speed;
		keyFrame = out;
		setFinished(false);
		
		
	}
	
	public ImageButton2(TextureRegion out, TextureRegion in, InvertedInput input, int xPos, int yPos, float speed){
		this.out = out;
		this.in = in;
		this.xPos = xPos;
		this.yPos = yPos;
		this.input = input;
		setTouched(false);
		bounds = new Rectangle(xPos, yPos, out.getRegionWidth(), out.getRegionHeight());
		this.speed = speed;
		keyFrame = out;
		setFinished(false);
		
		
	}
	
	public ImageButton2(Sprite out, Sprite in, InvertedInput input, int xPos, int yPos, float speed){
		this.sOut = out;
		this.sIn = in;
		this.xPos = xPos;
		this.yPos = yPos;
		this.input = input;
		setTouched(false);
		bounds = out.getBoundingRectangle();
		this.speed = speed;
		sKeyFrame = out;
		setFinished(false);
		
		
	}
	
	public ImageButton2(Texture button, int xPos, int yPos){
		this.button = button;
		this.xPos = xPos;
		this.yPos = yPos;
	}
	
	
	public Rectangle getBounds(){
		return bounds;
	}
	
	public void update(float deltaTime){
		
		if(!(input == null)){
			if(bounds.contains(input.getX(), input.getY()) && input.justTouched()){
				setTouched(true);
			}
		}
		
		
		if(isTouched()){
			sinceTouched += deltaTime;
			}
		
		if(sinceTouched < speed) keyFrame = out;
		else {
			 keyFrame = in;
			 setFinished(true);
			 }
		}
	

	public boolean isTouched() {
		return touched;
	}

	public boolean setTouched(boolean touched) {
		this.touched = touched;
		return touched;
	}

	public boolean isFinished() {
		return finished;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}
}


